import { baseModule } from "@/base/module";
import { LazyLoader } from "@sapi-game/gameComponent/common/lazyLoader";
import { GamePlayer } from "@sapi-game/gamePlayer/gamePlayer";
import { PlayerGroup } from "@sapi-game/gamePlayer/playerGroup";
import { DimensionIds } from "@sapi-game/utils/vanila-data";
import { KcpdBackDoorComponent } from "./door";
import { KcpdGameStarter } from "./starter";
import { KcpdWatingRoom } from "./watingRoom";
import { CubeRegion } from "@sapi-game/gameRegion/gameRegion";

export class KcpdBackState extends baseModule.State {
    readonly players = new PlayerGroup(GamePlayer);
    readonly region = new CubeRegion(
        DimensionIds.Overworld,
        { x: -138, y: -49, z: -373 },
        { x: -149, y: -58, z: -364 }
    );

    override onEnter(): void {
        this.addComponent(LazyLoader, {
            pos: { x: -147, y: -60, z: -387 },
            dimensionId: DimensionIds.Overworld,
            onLoad: (l) => this.onLoad(l),
            onUnload: () => {
                this.players.clear();
            },
        });
    }

    onLoad(loader: LazyLoader) {
        loader
            .addComponent(KcpdBackDoorComponent)
            .addComponent(KcpdGameStarter)
            .addComponent(KcpdWatingRoom);
    }
}
